package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.mapper.NtReviseMapper;
import com.csun.cmny.provider.model.domain.NtRevise;
import com.csun.cmny.provider.model.vo.ReviseVo;
import com.csun.cmny.provider.service.NtReviseService;
import com.csun.cmny.provider.service.OmcActivitiFeignApi;
import com.csun.cmny.provider.service.OmcReviseFeignApi;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-12-12 13:29
 * @Description:
 */
@Service
@Transactional
public class NtReviseServiceImpl extends BaseService<NtRevise> implements NtReviseService {

    @Resource
    private OmcActivitiFeignApi omcActivitiFeignApi;
    @Resource
    private NtReviseService ntReviseService;
    @Resource
    private OmcReviseFeignApi omcReviseFeignApi;
    @Resource
    private NtReviseMapper ntReviseMapper;

    /**
     * init revise process
     *
     * act_re_procdef
     * act_re_deployment
     * act_ge_bytearray
     *
     * @param homeId
     * @param groupId
     *
     * @return
     */
    @Override
    public Integer processInit(Integer homeId, Long groupId) {

        omcActivitiFeignApi.reviseProcessDeploymentCreate(groupId);

        return 0;
    }

    /**
     * init revise data
     *
     * @param homeId
     * @param groupId
     * @return
     */
    @Override
    public Integer reviseInit(Integer homeId, Long groupId) {

        // 查询指定机构的调房调级信息
        NtRevise ntRevise = new NtRevise();
        ntRevise.setHomeid(homeId);
//        ntRevise.setId(108);

        List<NtRevise> ntReviseList = ntReviseMapper.select(ntRevise);
        for (NtRevise r : ntReviseList) {

            // 查询老人的班组和姓名
            NtRevise tmp = ntReviseMapper.queryOldmanAndNursingGroupId(r.getOldid());
            r.oldmanName = tmp.oldmanName;
            r.nursingGroupId = tmp.nursingGroupId;

            // TODO 查询人工减免 ......

            ReviseVo reviseVo = new ReviseVo();
            //BeanUtils.copyProperties(r, reviseVo);
            reviseVo.setHomeId(homeId);
            reviseVo.setOldmanName(tmp.oldmanName);
            reviseVo.setNursingGroupId(tmp.nursingGroupId);

            reviseVo.setAgio(r.getAgio());
            reviseVo.setBedAt(r.getBedat());
            reviseVo.setBedBf(r.getBedbf());
            reviseVo.setBedFeesAt(r.getBedfeesat());
            reviseVo.setBedFeesBf(r.getBedfeesbf());
            reviseVo.setBedFeesBfRed(r.getBedfeesbfred());
            reviseVo.setBedFeesRed(r.getBedfeesred());
            reviseVo.setCreatetime(r.getCreatetime());
            reviseVo.setDays(r.getDays());
            reviseVo.setDesc(r.getDesc());
            reviseVo.setFeeRed(r.getFeered());
            reviseVo.setFeesAt(r.getFeesat());
            reviseVo.setFeesBf(r.getFeesbf());
            reviseVo.setFeesBfRed(r.getFeesbfred());
            reviseVo.setFoodAt(r.getFoodat());
            reviseVo.setFoodBf(r.getFoodbf());
            reviseVo.setFoodFeesAt(r.getFoodfeesat());
            reviseVo.setFoodFeesBf(r.getFoodfeesbf());
            reviseVo.setFoodFeesBfRed(r.getFoodfeesbfred());
            reviseVo.setFoodFeesRed(r.getFoodfeesred());
            reviseVo.setId(r.getId());
            reviseVo.setLevelAt(r.getLevelat());
            reviseVo.setLevelBf(r.getLevelbf());
            reviseVo.setModifytime(r.getModifytime());
            reviseVo.setOldmanId(r.getOldid());
            reviseVo.setProcessinstanceid(r.getProcessinstanceid());
            reviseVo.setReason(r.getReason());
            reviseVo.setReviseDate(r.getRevisedate());
            reviseVo.setServiceAt(r.getServiceat());
            reviseVo.setServiceBf(r.getServicebf());
            reviseVo.setServiceFeesAt(r.getServicefeesat());
            reviseVo.setServicefeesBf(r.getServicefeesbf());
            reviseVo.setServiceFeesBfRed(r.getServicefeesbfred());
            reviseVo.setServiceFeesRed(r.getServicefeesred());
            reviseVo.setState(r.getState());
            reviseVo.setValid(r.getValid());

            omcReviseFeignApi.initRevise(reviseVo);

            // omcReviseFeignApi.syncRevise(r);
        }

        return null;
    }

    @Override
    public Integer revise(Integer homeId, Long groupId) {
        return null;
    }
}
